package com.study.demo_jdbctemplate2.service;

import com.study.demo_jdbctemplate2.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.annotation.Resources;
import java.util.List;

/**
 * @ClassName: UserService
 * @Description:
 * @author: WS
 * @date 2020/12/14
 * @Version: 1.0
 **/
@Service
public class UserService {
    @Autowired
    @Qualifier("jdbcTemplate1")
    JdbcTemplate template1;
    @Resource(name="jdbcTemplate2")
    JdbcTemplate template2;

    public List<User> getAllUsers1(){
        String sql="select * from users";
        List<User> list = template1.query(sql, new BeanPropertyRowMapper<>(User.class));
        return list;
    }
    public List<User> getAllUsers2(){
        String sql="select * from users";
        List<User> list = template2.query(sql, new BeanPropertyRowMapper<>(User.class));
        return list;
    }
}
